﻿using Apps.Common;
using Apps.Models;
using Apps.Models.S;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Apps.BLL.S
{
    public partial class S_SAMPLEBLL
    {
        public DBContainer db = new DBContainer();

        public List<V_S_SAMPLE_RC> GetList_RC(ref GridPager pager, string batch,string rfid, string startcdate, string endcdate,
                string startdate, string enddate)
        {
            IQueryable<V_S_SAMPLE_RC> queryData = this.db.V_S_SAMPLE_RC.AsQueryable();
            if (!string.IsNullOrEmpty(batch))
            {
                queryData = queryData.Where(m => m.BATCH_CODE.Contains(batch));
            }
            if (!string.IsNullOrEmpty(rfid))
            {
                queryData = queryData.Where(m => m.RFID.Contains(rfid));
            }
            if (!string.IsNullOrEmpty(startcdate))
            {
                DateTime dCStartDate = DateTime.ParseExact(startcdate, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.CREATE_TIME >= dCStartDate);
            }
            if (!string.IsNullOrEmpty(endcdate))
            {
                DateTime dCEndDate = DateTime.ParseExact(endcdate, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.CREATE_TIME < dCEndDate);
            }
            if (!string.IsNullOrEmpty(startdate))
            {
                DateTime dStartDate = DateTime.ParseExact(startdate, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.WEIGHT_TIME >= dStartDate);
            }
            if (!string.IsNullOrEmpty(enddate))
            {
                DateTime dEndDate = DateTime.ParseExact(enddate, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.WEIGHT_TIME < dEndDate);
            }
            pager.totalRows = queryData.Count();
            //排序
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            return queryData.ToList();
        }

        public List<V_S_SAMPLE_RL> GetList_RL(ref GridPager pager,  string batch, string startcdate, string endcdate,
                string startdate, string enddate)
        {
            IQueryable<V_S_SAMPLE_RL> queryData = this.db.V_S_SAMPLE_RL.AsQueryable();
            if (!string.IsNullOrEmpty(batch))
            {
                queryData = queryData.Where(m => m.BATCH_CODE.Contains(batch));
            }
            if (!string.IsNullOrEmpty(startcdate))
            {
                DateTime dCStartDate = DateTime.ParseExact(startcdate, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.CREATE_TIME >= dCStartDate);
            }
            if (!string.IsNullOrEmpty(endcdate))
            {
                DateTime dCEndDate = DateTime.ParseExact(endcdate, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.CREATE_TIME < dCEndDate);
            }
            if (!string.IsNullOrEmpty(startdate))
            {
                DateTime dStartDate = DateTime.ParseExact(startdate, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.WEIGHT_TIME >= dStartDate);
            }
            if (!string.IsNullOrEmpty(enddate))
            {
                DateTime dEndDate = DateTime.ParseExact(enddate, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.WEIGHT_TIME < dEndDate);
            }
            pager.totalRows = queryData.Count();
            //排序
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            return queryData.ToList();
        }
    }
}
